home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.07 Jul 87 / bit map source / drag.p < prev    next >
Encoding:
Text File  |  1987-04-24  |  2.3 KB  |  97 lines  |  [TEXT/MPS ]

  1. program Fish;
  2. {$D+}    {put in debug names}
  3. {$R+}    {range checking on}
  4. {$OV+} {overflow checking on}
  5. {$N+}    {pass routine names to linker, so they're not anonymous}
  6. USES {$LOAD pinterfaces.dump}        
  7.         MemTypes,QuickDraw,OsIntf,PasLibIntf,ToolIntf,
  8.         PackIntf,IntEnv,CursorCtl,
  9.         {$LOAD}
  10.         {$U UDrag.p}    DragManager;
  11.  
  12. var
  13.     myPic : PicHandle;
  14.     myRect : Rect;
  15.     wPort: GrafPtr;
  16.     whichPict,
  17.     x,y,xinc,yinc : integer;
  18.     xyPt, lastXYPt : point;
  19.     myEventRecord : EventRecord;
  20.     lastCount : longint;
  21.     
  22.     myDragStuff : DragHandle;
  23.  
  24. procedure SwimItAround;
  25. const 
  26.     CapsLockBit = 10;
  27. var
  28.     hOffset : integer;
  29.     mousingRgn : RgnHandle;
  30.     mousePt: Point;
  31. begin
  32.     with shadowStuff do 
  33.         begin dx := 0; dy := 0;  visible := false; end;
  34.     with myPic^^.picFrame do
  35.         SetPt( lastXYPt, left-right, screenBits.bounds.bottom-(bottom-top) div 2 );
  36.     xyPt := lastXYPt;
  37.     hOffset := 2;
  38.     mousingRgn := NewRgn;
  39.     CopyRgn( myDragStuff^^.thePictureRgn, mousingRgn );
  40.     OffsetRgn( mousingRgn, -mousingRgn^^.rgnBBox.left,
  41.         -mousingRgn^^.rgnBBox.top);
  42.     OffsetRgn( mousingRgn, xyPt.h, xyPt.v );
  43. repeat
  44.     if button then 
  45.     begin
  46.         GetMouse( mousePt );
  47.         LocalToGlobal( mousePt );
  48.         if PtInRgn( mousePt,  mousingRgn) then hOffset := 20;
  49.     end;
  50.     xyPt.h := xyPt.h + hOffset;
  51.     xyPt.v := xyPt.v + (Random div 30000);
  52.     OffsetRgn( mousingRgn, -mousingRgn^^.rgnBBox.left,
  53.         -mousingRgn^^.rgnBBox.top);
  54.     OffsetRgn( mousingRgn, xyPt.h, xyPt.v );
  55.     
  56.     DragItTo( myDragStuff, xyPt, false );
  57.     lastXYPt := xyPt;
  58.     {allow for FKEY access and give DAs and such time}
  59.     if GetNextEvent( keyDownMask, myEventRecord ) then {do nothing};
  60.     SystemTask;
  61. until xyPt.h > screenBits.bounds.right 
  62.     + myPic^^.picFrame.right-myPic^^.picFrame.left;
  63. end; {dragitaround}
  64.  
  65. begin{main}
  66.     InitGraf(@thePort);
  67.     
  68. {standalones need to init windows, but tools shouldn't}
  69.     if IEStandalone then InitWindows;
  70.     
  71.     GetWMgrPort( wPort );
  72.     SetPort( wPort );
  73.     ClipRect( screenBits.bounds );
  74.     
  75.     if not InitDrag( nil ) then exit( Fish );
  76.     
  77.     myPic := GetPicture(197);
  78.     if myPic = nil then 
  79.         begin SysBeep(1); exit(Fish); end;
  80.         {change up the default shadow stuff}
  81.         with shadowStuff do
  82.         begin
  83.                 thePattern := gray;
  84.                 copyMode := SrcOr;
  85.         end;
  86.  
  87.     if not NewDraggable( myPic, nil, nil, myDragStuff )
  88.         then exit(Fish);
  89.     SwimItAround;    
  90.     DisposeDraggable( myDragStuff );
  91.     ReleaseResource( Handle( myPic ));
  92.  
  93. CloseDrag( true );
  94. FlushEvents( everyEvent, 0 );
  95.  
  96. end.
  97.